#include "Cube.h"


#define P(x,y,z) Point(x,y,z)
Cube::Cube(Point pos,float w,float l,float h)
{
	float w2 = w * 0.5, l2 = l * 0.5, h2 = h * 0.5;
	Point ftl(pos + P(-w2,-h2,-l2)),ftr(pos + P(w2,-h2,-l2)),fbl(pos + P(-w2,h2,-l2)),fbr(pos + P(w2,h2,-l2));
	Point btl(pos + P(-w2,-h2,l2)),btr(pos + P(w2,-h2,l2)),bbl(pos + P(-w2,h2,l2)),bbr(pos + P(w2,h2,l2));
	//printf("BeginCube\n");
	q[0] = Quad(ftl,ftr,fbr,fbl);
	q[1] = Quad(ftr,btr,bbr,fbr);
	q[2] = Quad(btr,btl,bbl,bbr);
	q[3] = Quad(btl,ftl,fbl,bbl);
	q[4] = Quad(btl,btr,ftr,ftl);
	q[5] = Quad(fbl,fbr,bbr,bbl);
	//printf("EndCube\n");
}


Cube::~Cube(void)
{
}

void Cube::mulMat( Mat4& mat )
{
	q[0].mulMat(mat);
	q[1].mulMat(mat);
	q[2].mulMat(mat);
	q[3].mulMat(mat);
	q[4].mulMat(mat);
	q[5].mulMat(mat);
}

void Cube::setTexture( Texture* texture,Vec3& uvPos/*=Vec3(0,0,0)*/,float uvW /*= 1.0*/,float uvH /*= 1.0*/ )
{
	q[0].setTexture(texture);
	q[1].setTexture(texture);
	q[2].setTexture(texture);
	q[3].setTexture(texture);
	q[4].setTexture(texture);
	q[5].setTexture(texture);
}

void Cube::draw( IPixelDrawer* dr )
{
	q[0].draw(dr);
	q[1].draw(dr);
	q[2].draw(dr);
	q[3].draw(dr);
	q[4].draw(dr);
	q[5].draw(dr);
}
